var submitDate = new Array();
$(function() {
	// upload plugin
	image_uplate_plugin();
	// text editor
	/*var editor = KindEditor.create('textarea[name="plate.plateDetail"]', {
		afterBlur : function() {
			this.sync();
		}
	});*/
	/*jQuery.validator.setDefaults({
		submitHandler : function(form) {
			form.submit(form);
		}
	});
	$.validator.addMethod("plateCode", function(value, element) {
		var reg = /^[a-zA-Z0-9]+$/;
		return this.optional(element) || reg.test(value);
	}, "输入必须为正整数和字母组合");

	$('#searchForm').validate({
		errorPlacement : function(error, element) {
			element.siblings("p[class='red']").text(error.text());
		},
		rules : {
			plateCode : {
				required : true,
				checkOrganizationCode : true
			},
			plateName : {
				required : true
			},
			plateTopSerial : {
				required : true
			},
			plateDescription : {
				required : true
			}
		},
		messages : {
			plateCode : {
				required : "请输入板块编码"
			},
			plateName : {
				required : "请输入板块名称"
			},
			plateTopSerial : {
				required : "请输入板块排序"
			},
			plateDescription : {
				required : "请输入板块描述"
			}
		}
	});*/
});

function image_uplate_plugin() {

	var plateId = $("#plateId").val();
	var count = 5-$("#imageCount").val();
	$("#uploader").plupload({
		// General settings
		runtimes : 'html5,flash,silverlight,html4',
		url : appServer + '/plate/upload_image.htm?plateId=' + plateId,
		// User can upload no more then 20 files in one go (sets multiple_queues
		// to false)
		max_file_count : count,

		chunk_size : '10MB',

		// Resize images on clientside if we can

		filters : {
			// Maximum file size
			max_file_size : '5MB',
			// Specify what files to browse for
			mime_types : [ {
				title : "Image files",
				extensions : "jpg,jpeg,gif,png"
			}

			]
		},

		// Rename files by clicking on their titles
		rename : false,

		// Sort files
		sortable : true,

		// Enable ability to drag'n'drop files onto the widget (currently only
		// HTML5 supports that)
		dragdrop : true,

		// Views to activate
		views : {
			list : true,
			thumbs : true, // Show thumbs
			active : 'thumbs'
		},

		// Flash settings
		flash_swf_url : appServer + '/scripts/plupload/Moxie.swf',

		// Silverlight settings
		silverlight_xap_url : appServer + '/scripts/plupload/Moxie.xap',
		init : {

			UploadComplete : function(up, files) {
				//image_uplate_plugin();
				alert(up.data.data);
			}
		}
	});

}

function updateLogo() {
	var id=$("#plateId").val();
	var fileInfo=$("#uploadFile").val();
	var arr = fileInfo.split('\\');	
	$.ajaxFileUpload({
		type:"post",
		url:appServer + "/plate/ajax/updateLogo.htm", //用于文件上传的服务器端请求地址
		secureuri : false, //是否需要安全协议，一般设置为false
        fileElementId : 'uploadFile', //文件上传域的ID
        data:{"plateId":id},
        dataType : 'json', //返回值类型 一般设置为json
        success : function(result) {
        	$("#fileInfo").html(arr[arr.length-1]);
        	$('#fileImage').empty();
        	$('#fileImageTile').empty();
        	$("#fileImageTile").append("<span style='color:red'>*</span>logo缩略图：");
        	$("#fileImage").append("<img src='"+imageServer+"/"+result.data+"' width='80px'/>");
        },
        error: function (data, status, e){
        	alert('导入logo失败！');
        }
	});
}